

<template>
<div>
  <h2>child1</h2>
  <div>
    接收弟弟的消息：{{ reciverMsg }}
  </div>
  <div>
    <el-button type="primary" @click="sendMsg">发送消息给父</el-button>
  </div>
</div>
</template>
<script setup lang="ts">
import emitter from '@utils/emitter.ts'
const msg1 = ref('msg——1')

const sendMsg = ()=>{
  emitter.emit('child1Msg', msg1)
}

 const reciverMsg = ref('')
emitter.on('sendMsgToBrother', (val:string)=>{
  console.log('接收弟弟的消息：',val)
  reciverMsg.value = val
})

onBeforeUnmount(()=>{
  emitter.off('sendMsgToBrother')
})
</script>
<style scoped>

</style>
